﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace Corona
{
	/// <summary>
	/// AttributeEditer.xaml 的交互逻辑
	/// </summary>
	public partial class AttributeEditer
	{
        
		public AttributeEditer()
		{
			this.InitializeComponent();
		}
        private TagInfoItems items = new TagInfoItems();

        #region 拖拽操作

        private bool IsDragging = false;
        private Button senderObject;
        private double offsetX;
        private double offsetY;

        private void Drag_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            IsDragging = true;
            senderObject = sender as Button;

            offsetX = e.GetPosition(senderObject).X;
            offsetY = e.GetPosition(senderObject).Y;

            Canvas.SetZIndex(this, Int32.MaxValue);
        }
        private void Drag_OnMouseMove(object sender, MouseEventArgs e)
        {
            if (IsDragging)
            {
                Canvas parentCanvas = this.Parent as Canvas;

                double currentX = e.GetPosition(ParentCanvas).X;
                double currentY = e.GetPosition(ParentCanvas).Y;

                Canvas.SetLeft(MainGrid, currentX - offsetX);
                Canvas.SetTop(MainGrid, currentY - offsetY);
            }
        }
        private void Drag_OnMouseUp(object sender, MouseButtonEventArgs e)
        {
            IsDragging = false;
        }
        #endregion

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnLoad(object sender, RoutedEventArgs e)
        {
            items.Add(new TagInfoItem("test", "sdfsdf"));
            items.Add(new TagInfoItem("Type", "jpg(xxxxx)"));
            items.Add(new TagInfoItem("Date", "May 12th, Mon."));
            items.Add(new TagInfoItem("风格", "传统"));
            TagListView.ItemsSource = items;
        }
        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(items["test"].Value.ToString());
        }
	}
    /// <summary>
    /// 单个标签信息
    /// </summary>
    public class TagInfoItem
    {
        private string _Type;
        private string _Value;
        public string Type
        {
            set { _Type = value; }
            get { return _Type; }
        }
        public string Value
        {
            set { _Value = value; }
            get { return _Value; }
        }
        public TagInfoItem(string type, string value)
        {
            this.Type = type;
            this.Value = value;
        }
    }
    /// <summary>
    /// 标签信息列表
    /// </summary>
    public class TagInfoItems :
        ObservableCollection<TagInfoItem>
    {
        public TagInfoItems()
        {

        }
        public TagInfoItem this[String type]
        {
            get
            {
                foreach (TagInfoItem item in Items)
                    if (item.Type == type)
                        return item;
                return null;
            }
        }
    }
}